<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title>Signin Template for Bootstrap</title>
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<link href="css/signin.css" rel="stylesheet">
<script src="dist/js/jquery-3.3.1.min.js"></script>
<script src="layer.js"></script>
<script src="layui.js"></script>
<link rel="stylesheet" href="css/layui.css" media="all">
</head>

<body>

	<div class="container">

		<form class="form-signin">
			<h2 class="form-signin-heading">请登录</h2>
			<div id="msg" style="display: none;"></div>
			<label for="userNameLogin" class="sr-only">用户名</label> <input
				type="text" name="userNameLogin" id="userNameLogin"
				class="form-control" placeholder="用户名" required autofocus> <label
				for="passWordLogin" class="sr-only">密码</label> <input
				type="password" id="passWordLogin" name="passWordLogin"
				class="form-control" placeholder="密码" required>
			<div class="checkbox">
				<label> <input type="checkbox" value="remember-me">
					记住我
				</label>
			</div>
			<button id="btnLogin" class="btn btn-lg btn-primary btn-block"
				type="button">登录</button>
		</form>

	</div>
	<script type="text/javascript">
		$(function() {
			//前台登录功能
			$("#btnLogin").click(function() {
				console.log(1111);
				//ajax请求
				$.ajax({
					url : "QuestionTopServlet?op=userLogin",//url地址
					type : "post",
					data : {
						"userNameLogin" : $('#userNameLogin').val(),
						"passWordLogin" : $('#passWordLogin').val()//传值
					},
					//成功后执行的操作
					success : function(data) {
						//判断用户名密码是否正确，正确的话则跳到前台首页
						if (data == "false") {
							$("#msg").css("display", "block");
							$("#msg").css("color", "red");
							$("#msg").text("账号或密码错误");
						} else {
							layer.msg('登录成功   请关闭此窗口并刷新主页面愉快的玩耍吧！！', {
								time : 3000, //20s后自动关闭
								btn : [ '知道了' ]
							}, function() {
								location.href = "QuestionTopServlet?op=queryquestion_jstl&req=front"
								window.parent.location.reload();
							});
						}
					}
				});
			});

		}); 
	</script>
</body>
</html>
